# import rpmfile
#
# with rpmfile.open('MySQL-python-1.2.3-0.3.c1.1.el6.src.rpm') as rpm:
#
#     # Inspect the RPM headers
#     print(rpm.headers)
#     print(rpm.headers.keys())
#     print(rpm.headers.get('arch', 'noarch'))
#
#     # Extract a fileobject from the archive
#     # fd = rpm.extractfile("MySQL-python.spec")
#     # with open("tt.spec", "wb") as qqq:
#     #     qqq.write(fd.read())
#
#     for member in rpm.getmembers():
#         print(member)
#
#
# # with rpmfile.open('rpm-4.11.3-25.el7.centos.1.x86_64.rpm') as rpm:
# #
# #     # Inspect the RPM headers
# #     print(rpm.headers.keys())
# #     print(rpm.headers.get('arch', 'noarch'))
# #
# #     # Extract a fileobject from the archive
# #     # fd = rpm.extractfile("MySQL-python.spec")
# #     # with open("tt.spec", "wb") as qqq:
# #     #     qqq.write(fd.read())
# #     print(rpm.headers)
# #     for member in rpm.getmembers():
# #         print(member)
#
#
import os.path
import sys
#############iso
# https://github.com/clalancette/pycdlib/blob/master/examples/open-existing.py
import pycdlib

# Create a new PyCdlib object.
iso = pycdlib.PyCdlib()
# Open up a file object.  This causes PyCdlib to parse all of the metadata on the
# ISO, which is used for later manipulation.
iso.open("D:/ISO/Fedora-Server-dvd-x86_64-36-1.5.iso")

# Now iterate through each of the files on the root of the ISO, printing out
# their names.
for child in iso.list_children(iso_path='/repodata'):
    print(child.file_identifier())
print(dir(iso))
iso.get_file_from_iso("iso_test/9d078581db64877d115e36ee67b2794a756fe396bae04c79bb671d9c1f5ebaac-other.sqlite.xz", iso_path="/repodata/9d078581db64877d115e36ee67b2.x")

# Close the ISO object.  After this call, the PyCdlib object has forgotten
# everything about the previous ISO, and can be re-used.
iso.close()

# ############rpm 提取
# import rpmfile
# with rpmfile.open('MySQL-python-1.2.3-0.3.c1.1.el6.src.rpm') as rpm:
#     for member in rpm.getmembers():
#         print(member.name)
#         fd = rpm.extractfile(member.name)
#         with open(os.path.join("rpm_test", member.name), "wb") as f:
#             f.write(fd.read())
